// Controller.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "ControllerBase.h"
#include "../Infobus/ComponentRegister.h"

#ifdef _MANAGED
#pragma managed(push, off)
#endif

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

#ifdef _MANAGED
#pragma managed(pop)
#endif

ControllerBase::ControllerBase()
: IListener(ACTIONS)
{
  setAliveBeats(true);
  ComponentRegister::getInstance()->enableRedundancy(IListener::getSender(), IListener::getSubjectText(), true);
}

ControllerBase::~ControllerBase()
{

}

bool ControllerBase::isMaster()
{
  return ComponentRegister::getInstance()->isMaster(IListener::getSender());
}


void ControllerBase::setMaster(bool promote)
{
  if (ComponentRegister::getInstance()->isRedundant(this->getSender())) {
    ComponentRegister::getInstance()->setMaster(this->getSender(), promote);
  }
}